﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI.TraCuu_Update
{
    public partial class QuiDinhGUI : UserControl, GUI.UctrlGUI
    {
        BLL.QuiDinhBLL _QuiDinhBLL;

        public QuiDinhGUI()
        {
            InitializeComponent();
            _QuiDinhBLL = new BLL.QuiDinhBLL();
            
        }

        private void QuiDinhGUI_Load(object sender, EventArgs e)
        {
            txt_NhapToiThieu.Text = _QuiDinhBLL.NhapToiThieu.ToString();
            txt_NoToiDa.Text = _QuiDinhBLL.NoToiDa.ToString();
            txt_TonToiDa.Text = _QuiDinhBLL.TonToiDa.ToString();
            txt_TonToiThieu.Text = _QuiDinhBLL.TonToiThieu.ToString();
            chb_QD4.Checked = _QuiDinhBLL.QD4;
        }

        private void btn_CapNhat_Click(object sender, EventArgs e)
        {
            _QuiDinhBLL.NhapToiThieu = int.Parse(txt_NhapToiThieu.Text);
            _QuiDinhBLL.NoToiDa = float.Parse(txt_TonToiDa.Text);
            _QuiDinhBLL.TonToiDa = int.Parse(txt_TonToiDa.Text);
            _QuiDinhBLL.TonToiThieu = int.Parse(txt_TonToiThieu.Text);
            _QuiDinhBLL.QD4 = chb_QD4.Checked;
        }

        public String getName()
        {
            return "TRA CỨU QUI ĐỊNH";
        }

        private void txt_NhapToiThieu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) &&
                !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void txt_TonToiDa_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) &&
                !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void txt_TonToiThieu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) &&
                !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void txt_NoToiDa_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) &&
                !char.IsDigit(e.KeyChar) &&
                e.KeyChar != '.')
                e.Handled = true;
            if (e.KeyChar == '.' &&
                (sender as TextBox).Text.IndexOf('.') > -1)
                e.Handled = true;
        }
    }
}
